
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
postcss-custom-property-prefixer
Advanced tools
Add prefix to your css custom-property
<npm/yarn/pnpm> i -D postcss-custom-property-prefixer
Then register this plugin into your postcss.config.js
:
module.exports = {
plugins: {
// ...
'postcss-custom-property-prefixer': {
// prefix option must be passed!
prefix: 'ice-'
}
// ...
}
}
.a {
--tab-color: hsl(var(--bc) / var(--tw-text-opacity, 1));
--tab-bg: hsl(var(--b1) / var(--tw-bg-opacity, 1));
--tab-border-color: hsl(var(--b3) / var(--tw-bg-opacity, 1));
}
Will be transformed to:
.a {
--ice-tab-color: hsl(var(--ice-bc) / var(--ice-tw-text-opacity, 1));
--ice-tab-bg: hsl(var(--ice-b1) / var(--ice-tw-bg-opacity, 1));
--ice-tab-border-color: hsl(var(--ice-b3) / var(--ice-tw-bg-opacity, 1));
}
Not right? Yes! Default this plugin will transform all css custom property
!
If you want to ignore some custom properties
like --tw-*
, you should pass some ignore*
options, See Below!
Css nodes are generated by tailwindcss
, because it's custom property
all start with '--tw-'
, so you can pass options like below.
'postcss-custom-property-prefixer': {
// your custom prefix
prefix: 'ice-',
ignoreValueCustomProperty(cp, decl) {
// ignore value
return cp.startsWith('--tw-')
},
ignoreProp(decl) {
// ignore prop
return decl.prop.startsWith('--tw-')
}
}
plugin options:
'postcss-custom-property-prefixer': {
prefix: 'ice-',
ignoreValueCustomProperty(cp) {
return cp.startsWith('--tw-')
}
}
Before:
.a {
/* ⬇ --tw-* */
--tab-color: hsl(var(--bc) / var(--tw-text-opacity, 1));
/* ⬇ --tw-* */
--tab-bg: hsl(var(--b1) / var(--tw-bg-opacity, 1));
/* ⬇ --tw-* */
--tab-border-color: hsl(var(--b3) / var(--tw-bg-opacity, 1));
}
After:
.a {
--ice-tab-color: hsl(var(--ice-bc) / var(--tw-text-opacity, 1));
--ice-tab-bg: hsl(var(--ice-b1) / var(--tw-bg-opacity, 1));
--ice-tab-border-color: hsl(var(--ice-b3) / var(--tw-bg-opacity, 1));
}
See! All css decl's value's custom properties which start with --tw-
are ignored!
This option will ignore the whole decl!
'postcss-custom-property-prefixer': {
prefix: 'ice-',
ignoreDecl(decl) {
return decl.prop === '--tab-color' || decl.value.includes('hsl(var(--b1)')
},
ignoreValueCustomProperty(cp) {
return cp.startsWith('--tw-')
}
}
Before:
.a {
/* prop === --tab-color , this decl will be ignored */
--tab-color: hsl(var(--bc) / var(--tw-text-opacity, 1));
/* value.includes('hsl(var(--b1)') , this will be ignored */
--tab-bg: hsl(var(--b1) / var(--tw-bg-opacity, 1));
/* will be transformed */
--tab-border-color: hsl(var(--b3) / var(--tw-bg-opacity, 1));
}
After:
.a {
--tab-color: hsl(var(--bc) / var(--tw-text-opacity, 1));
--tab-bg: hsl(var(--b1) / var(--tw-bg-opacity, 1));
--ice-tab-border-color: hsl(var(--ice-b3) / var(--tw-bg-opacity, 1));
}
'postcss-custom-property-prefixer': {
prefix: 'ice-',
ignoreProp(decl) {
return decl.prop === '--tab-color'
},
ignoreValueCustomProperty(cp) {
return cp.startsWith('--tw-')
}
}
Before:
.a {
/* ⬇ only ignore the prop , not value ⬇ */
--tab-color: hsl(var(--bc) / var(--tw-text-opacity, 1));
--tab-bg: hsl(var(--b1) / var(--tw-bg-opacity, 1));
--tab-border-color: hsl(var(--b3) / var(--tw-bg-opacity, 1));
}
After:
.a {
/* ⬇ target prop */
--tab-color: hsl(var(--ice-bc) / var(--tw-text-opacity, 1));
--ice-tab-bg: hsl(var(--ice-b1) / var(--tw-bg-opacity, 1));
--ice-tab-border-color: hsl(var(--ice-b3) / var(--tw-bg-opacity, 1));
}
'postcss-custom-property-prefixer': {
prefix: 'ice-',
ignoreValue(decl) {
return decl.value.includes('hsl(var(--b3)')
},
ignoreValueCustomProperty(cp) {
return cp.startsWith('--tw-')
}
}
Before:
.a {
--tab-color: hsl(var(--bc) / var(--tw-text-opacity, 1));
--tab-bg: hsl(var(--b1) / var(--tw-bg-opacity, 1));
/* ⬇ target value , ignored*/
--tab-border-color: hsl(var(--b3) / var(--tw-bg-opacity, 1));
}
After:
.a {
--ice-tab-color: hsl(var(--ice-bc) / var(--tw-text-opacity, 1));
--ice-tab-bg: hsl(var(--ice-b1) / var(--tw-bg-opacity, 1));
--ice-tab-border-color: hsl(var(--b3) / var(--tw-bg-opacity, 1));
}
Type: String
|PrefixFunction
, The prefix
will be add to all custom property
!
export type PrefixFunction = (decl: Declaration, target: 'prop' | 'value') => string
'postcss-custom-property-prefixer': {
prefix: (decl,target)=>{
if (target === 'prop' && decl.prop.startsWith('--bg-')) {
return 'aaa-'
}
if (target === 'value' && decl.prop.startsWith('--text-')) {
return 'bbb-'
}
return ''
},
}
Before:
.a {
--bg-red: hsl(var(--text-red-100));
--text-red: hsl(var(--text-red-500));
}
After:
.a {
--aaa-bg-red: hsl(var(--text-red-100));
--text-red: hsl(var(--bbb-text-red-500));
}
Type: Same as prefix
you can pass different prefix to prop
and value
:
'postcss-custom-property-prefixer': {
prefix: 'ice-',
propPrefix: 'xx-',
ignoreValueCustomProperty(cp) {
return cp.startsWith('--tw-')
}
}
.a {
--tab-color: hsl(var(--bc) / var(--tw-text-opacity, 1));
--tab-bg: hsl(var(--b1) / var(--tw-bg-opacity, 1));
--tab-border-color: hsl(var(--b3) / var(--tw-bg-opacity, 1));
}
After:
.a {
--xx-tab-color: hsl(var(--ice-bc) / var(--tw-text-opacity, 1));
--xx-tab-bg: hsl(var(--ice-b1) / var(--tw-bg-opacity, 1));
--xx-tab-border-color: hsl(var(--ice-b3) / var(--tw-bg-opacity, 1));
}
Boolean
: whether transform css decl's prop, default: true
Boolean
: whether transform css decl's value, default: true
MIT License © 2023-PRESENT sonofmagic
FAQs
Add prefix to your css custom-property
The npm package postcss-custom-property-prefixer receives a total of 2 weekly downloads. As such, postcss-custom-property-prefixer popularity was classified as not popular.
We found that postcss-custom-property-prefixer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.